from selenium import webdriver
import unittest
import time
from selenium.webdriver.common.by import By
from Zk_2211A.Zk_3.Page.Page import Page

class Case(unittest.TestCase):

    def setUp(self):
        # 打开edge浏览器
        self.driver = webdriver.Edge()
        # 窗口最大化
        self.driver.maximize_window()


    def tearDown(self):
        # 刷新浏览器
        self.driver.refresh()
        # 关闭浏览器
        self.driver.close()

    # 登录
    def test_01_jiuxian(self):
        # 初始化page页
        po = Page(self.driver)
        # 打开酒仙网
        po.open_url('https://www.jiuxian.com/')
        # 点击请登录
        po.please_login()
        # 输入账号
        po.send_user()
        # 输入密码
        po.send_pwd()
        time.sleep(15)
        # 点击登录按钮
        po.click_login()
        # 点击弹窗确定
        po.click_alert()
        time.sleep(3)
        # 文本断言，登录返回账户名一致
        dy = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
        self.assertEqual('jxw862943923', dy)

    # 添加地址
    def test_02_add(self):
        # 初始化page页
        po = Page(self.driver)
        # 调用登录业务
        po.login_jiuxian()
        # 点击我的酒仙
        po.click_my()
        # 关闭弹窗
        po.close_alert()
        time.sleep(2)
        # 断言确定进入我的酒仙页面
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/h1/a/span').text
        self.assertTrue('我的酒仙', dy2)
        # 滚动
        po.scrollTo(600)
        # 点击收货地址
        po.click_address()
        # 输入收货人
        po.send_shr()
        # 选择地区
        po.address_select()
        # 输入详细地址
        po.send_xxaddress()
        # 输入邮政编码
        po.send_zipcode()
        # 输入手机号
        po.send_iphone()
        # 点击提交
        po.click_tj()
        # 点击确定
        po.cilck_qd()

    # 删除地址
    def test_03_delete(self):
        # 初始化page页
        po = Page(self.driver)
        # 调用登录业务
        po.login_jiuxian()
        # 点击我的酒仙
        po.click_my()
        # 关闭弹窗
        po.close_alert()
        time.sleep(2)
        # 断言确定进入我的酒仙页面
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/h1/a/span').text
        self.assertTrue('我的酒仙', dy2)
        # 滚动
        po.scrollTo(600)
        # 点击收货地址
        po.click_address()
        # 点击删除
        po.click_delete()
        # 点击确定
        po.click_qd2()
        time.sleep(2)
        # 断言删除成功
        dy3 = self.driver.find_element(By.XPATH, '/html/body/div[8]/div/div[2]/p/span').text
        self.assertIn('成功', dy3)
        # 点击确定
        po.click_qd_delete()

if __name__ == '__main__':
    unittest.main()